# encoding: utf-8
# @project: st2111 
# @file: 06_request_post.py
# @time: 2023/3/30 14:23
# @author: abcque
# @license: (C) Copyright 2013-2021
# @contact: abcque@outlook.com
# @IDE: PyCharm
# @desc:
from urllib.parse import urlencode
from urllib.request import Request, urlopen

if __name__ == "__main__":
    url = "https://httpbin.org/post"

    data = {
        "user": "abc",
        "password":123456,
    }

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
    }

    data = urlencode(data)
    print(data)
    data = data.encode("utf-8")
    print(data)
    req = Request(url=url, data=data, headers=headers)

    resp = urlopen(req)

    content = resp.read()
    result = content.decode("utf-8")
    print(result)
